"use strict";

!function() {
    function errorLog(msg, url, lineNo, columnNo, error) {
        if ("Script error." !== msg && "The browser is shutting down." !== msg) {
            var req = new XMLHttpRequest(), timerAbort = null, errorData = {
                applicationId: "block-yourself-from-analytics",
                applicationType: "extension",
                applicationPlatform: "chrome",
                applicationVersion: chrome.runtime.getManifest().version,
                type: "error",
                message: msg,
                extra: {
                    extensionId: chrome.runtime.id,
                    url: url,
                    lineNo: lineNo,
                    columnNo: columnNo,
                    error: error,
                    stack: error && error.stack ? error.stack : null
                }
            };
            req.onreadystatechange = function() {
                if (4 === req.readyState && 200 === req.status) try {
                    if (timerAbort) {
                        window.clearTimeout(timerAbort);
                        timerAbort = null;
                    }
                    var doc = JSON.parse(req.responseText);
                    doc && window.console.log(doc);
                } catch (e) {
                    window.console.error(e);
                }
            };
            req.onerror = function(e) {
                window.console.error(e);
            };
            timerAbort = window.setTimeout(function() {
                req.abort();
            }, 1e4);
            req.open("POST", "https://api.yunnan.ws/v1/logs", !0);
            req.setRequestHeader("Content-type", "application/json; charset=UTF-8");
            req.send(JSON.stringify(errorData));
            return !1;
        }
    }
    window.onerror = errorLog;
    var consoleErrorFunc = window.console.error;
    window.console.error = function() {
        var argumentsArray = [];
        for (var argument in arguments) argumentsArray.push(arguments[argument]);
        consoleErrorFunc.apply(window.console, argumentsArray);
        errorLog(1 === argumentsArray.length && "string" == typeof argumentsArray[0] ? argumentsArray[0] : JSON.stringify(function destroyCircular(from, seen) {
            var commonProperties = [ "name", "message", "stack", "code" ], to = Array.isArray(from) ? [] : {};
            seen.push(from);
            for (var entries = Object.entries(from), i = 0; i < entries.length; i++) {
                var key = entries[i][0], value = entries[i][1];
                "function" != typeof value && (value && "object" == typeof value ? seen.includes(from[key]) ? to[key] = "[Circular]" : to[key] = destroyCircular(from[key], seen.slice()) : to[key] = value);
            }
            for (var j = 0; j < commonProperties.length; j++) {
                var property = commonProperties[j];
                "string" == typeof from[property] && (to[property] = from[property]);
            }
            return to;
        }(argumentsArray, [])), document.location.href, 0, 0, new Error());
    };
}();